import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBEngineer/YBBaseRouter/YBApplication.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBEngineer/YBWeChatPopPage/YBCameraSelectPopPage.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBImageStyle/YBImageStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/yb_chinese_text/yb_chinese_text.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBMineModule/YBMineProvider/YBMineZuZhiManagerProvider.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBMineModule/YBQiYePersonPage/YBNumberManagerProvider/YBQuanCengHomeInputEventBus.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBNetWorkModule/YBAPi/YBAPi.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBNetWorkModule/YBBaseMineNetWork/YBBaseMineNetWork.dart';




class YBQuanCengHomePage extends StatelessWidget {


  @override
  Widget build(BuildContext context) {


    return Container(
      child: Scaffold(
        appBar: AppBar(
          title: Text(YBChineseText.mineQuanCengHomeTitle,style: YBTextStyle.TextStyle30313320Medium,),
          elevation: 0,
        ),
        body: ChangeNotifierProvider(
            create: (context) => YBMineQuanCengHomeProvider()..getMineQuanCengHomeData(),
            child: Consumer<YBMineQuanCengHomeProvider>(
                builder: (context,quanCengHomeModel,child){

                  quanCengHomeInputEventBus.on<YBQuanCengHomeInputEventBus>().listen((event) {
                     quanCengHomeModel.getMineQuanCengHomeData();
                  });

                  return SingleChildScrollView(
                    child: Column(
                      children: <Widget>[
                        Container(
                          height: YBTextStyle.adapterSize8,
                        ),
                        Container(
                          height: YBTextStyle.adapterSize88,
                          color: YBColor.white,
                          child: Padding(
                            padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                            child: Container(
                              child: Row(
                                children: [
                                  Container(
                                    child: Image.asset(YBImageStyle.getImagePath('mine_teamInfo')),
                                  ),
                                  Container(
                                    width: YBTextStyle.adapterSize12,
                                  ),
                                  Expanded(
                                    child: Column(
                                      mainAxisAlignment: MainAxisAlignment.center,
                                      crossAxisAlignment: CrossAxisAlignment.start,
                                      children: [
                                        Container(
                                          child: Text(
                                            quanCengHomeModel.quanCengHomeModel.companyName??"",
                                            style: YBTextStyle.TextStyle2F303316Medium,
                                          ),
                                        ),

                                      ],
                                    ),
                                  ),
                                  Container(
                                    child: Text(
                                      YBChineseText.mineAuthTitle,
                                      style: YBTextStyle.TextStyleA9AEB812,
                                    ),
                                  ),
                                  Container(
                                    width: YBTextStyle.adapterSize5,
                                  ),
                                  Container(
                                    child: Image.asset(YBImageStyle.getImagePath('mine_orgianAuth')),
                                  ),
                                  Container(
                                    width: YBTextStyle.adapterSize8,
                                  ),
                                  Container(
                                    child: Image.asset(YBImageStyle.getImagePath('findIconArrowRight')),
                                  )
                                ],
                              ),
                            ),
                          ),
                        ),
                        Container(
                          height: YBTextStyle.adapterSize8,
                        ),
                        Container(
                          child:InkWell(
                            child: getCompanyKaiGuanLoadInfo(quanCengHomeModel.quanCengHomeModel.upStatus == 1?true:false),
                          ),
                        ),
                        Container(
                          child:InkWell(
                            child: getCompanyLogoLoadInfo('${YBApi.Base_image_URL}/${quanCengHomeModel.quanCengHomeModel.brandLogo}',context),
                          ),
                        ),
                        Container(
                          child:InkWell(
                            child: getCompanyLoadInfo(YBChineseText.minePinPaiMingChengTitle, quanCengHomeModel.quanCengHomeModel.brandName),
                            onTap: () async{
                              YBApplication.router.navigateTo(context, '/mine/mineQiYePersonPage/mineQuanCengHomePage/mineQuanCengHomeEditingPage?titleHeader=${Uri.encodeComponent("品牌名称")}&&contentTitle=${Uri.encodeComponent(quanCengHomeModel.quanCengHomeModel.brandName)}');
                            },
                          ),
                        ),
                        Container(
                          child:InkWell(
                            child: getCompanyLoadInfo(YBChineseText.mineLianXiPersonTitle, quanCengHomeModel.quanCengHomeModel.linkName),
                            onTap: () async {
                              YBApplication.router.navigateTo(context, '/mine/mineQiYePersonPage/mineQuanCengHomePage/mineQuanCengHomeEditingPage?titleHeader=${Uri.encodeComponent("联系人")}&&contentTitle=${Uri.encodeComponent(quanCengHomeModel.quanCengHomeModel.linkName)}');
                            },
                          ),
                        ),
                        Container(
                          child:InkWell(
                            child: getCompanyLoadInfo(YBChineseText.mineLianXiTelPhoneTitle, quanCengHomeModel.quanCengHomeModel.linkPhone),
                            onTap: () async {
                              YBApplication.router.navigateTo(context, '/mine/mineQiYePersonPage/mineQuanCengHomePage/mineQuanCengHomeEditingPage?titleHeader=${Uri.encodeComponent("联系电话")}&&contentTitle=${quanCengHomeModel.quanCengHomeModel.linkPhone}');
                            },
                          ),
                        ),
                        Container(
                          height: YBTextStyle.adapterSize8,
                        ),
                        Container(
                          child:InkWell(
                            child: getCompanyLoadInfo(YBChineseText.mineCityNameTitle, quanCengHomeModel.quanCengHomeModel.cityName),
                            onTap: () async {
                              YBApplication.router.navigateTo(context, '/mine/mineQiYePersonPage/mineQuanCengHomePage/mineQuanCengHomeEditingPage?titleHeader=${Uri.encodeComponent("城市")}&&contentTitle=${Uri.encodeComponent(quanCengHomeModel.quanCengHomeModel.cityName)}');
                            },
                          ),
                        ),
                        Container(
                          child:InkWell(
                            child: getCompanyLoadInfo(YBChineseText.mineAddressTitle, quanCengHomeModel.quanCengHomeModel.address),
                            onTap: () async {
                              YBApplication.router.navigateTo(context, '/mine/mineQiYePersonPage/mineQuanCengHomePage/mineQuanCengHomeEditingPage?titleHeader=${Uri.encodeComponent("地址")}&&contentTitle=${Uri.encodeComponent(quanCengHomeModel.quanCengHomeModel.address)}');
                            },
                          ),
                        ),
                        Container(
                          child:InkWell(
                            child: getCompanyLoadInfo(YBChineseText.mineWangZhiTitle, quanCengHomeModel.quanCengHomeModel.customerUrl),
                            onTap: () async {
                              YBApplication.router.navigateTo(context, '/mine/mineQiYePersonPage/mineQuanCengHomePage/mineQuanCengHomeEditingPage?titleHeader=${Uri.encodeComponent("网址")}&&contentTitle=${quanCengHomeModel.quanCengHomeModel.customerUrl}');
                            },
                          ),
                        ),
                        Container(
                          child:InkWell(
                            child: getCompanyLoadInfo(YBChineseText.mineEmailTitle, quanCengHomeModel.quanCengHomeModel.email),
                            onTap: () async {
                              YBApplication.router.navigateTo(context, '/mine/mineQiYePersonPage/mineQuanCengHomePage/mineQuanCengHomeEditingPage?titleHeader=${Uri.encodeComponent("邮箱")}&&contentTitle=${quanCengHomeModel.quanCengHomeModel.email}');
                            },
                          ),
                        ),
                        Container(
                          child:InkWell(
                            child: getCompanyLoadInfo(YBChineseText.mineJianJietitle, quanCengHomeModel.quanCengHomeModel.detail),
                            onTap: () async {
                              YBApplication.router.navigateTo(context, '/mine/mineQiYePersonPage/mineQuanCengHomePage/mineQuanCengHomeEditingPage?titleHeader=${Uri.encodeComponent("简介")}&&contentTitle=${Uri.encodeComponent(quanCengHomeModel.quanCengHomeModel.detail)}');
                            },
                          ),
                        ),
                      ],
                    ),
                  );
                }
            ),
        ),
      ),
    );
  }

  Widget getCompanyLoadInfo(String title, String bodyTitle){
    return Container(
      color: YBColor.white,
      height: YBTextStyle.adapterSize58,
      child: Padding(
        padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
        child: Row(
          children: [
            Container(
              child: Text(
                title,
                style: YBTextStyle.TextStyle2F303314,
              ),
            ),
            Expanded(
              child: Container(
                alignment: Alignment.centerRight,
                child: Text(
                  bodyTitle,
                  style: YBTextStyle.TextStyle2F303314,
                ),
              ),
            ),
            Container(
              width: YBTextStyle.adapterSize5,
            ),
            Container(
              child: Image.asset(YBImageStyle.getImagePath('findIconArrowRight')),
            ),
          ],
        ),
      ),
    );
  }

  Widget getCompanyKaiGuanLoadInfo(bool bodyBool){
    return Container(
      color: YBColor.white,
      height: YBTextStyle.adapterSize58,
      child: Padding(
        padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
        child: Row(
          children: [
            Container(
              child: Text(
                YBChineseText.mineJiaRuQuanCengTitle,
                style: YBTextStyle.TextStyle2F303314,
              ),
            ),
            Spacer(),
            Container(
              child: CupertinoSwitch(value: bodyBool, onChanged:(body){
                  print('--------------------$body----------------------');
                  if(body == false){
                    _editingQuanCengHome(0);
                  }else{
                    _editingQuanCengHome(1);
                  }
              }),
            ),
          ],
        ),
      ),
    );
  }

  Widget getCompanyLogoLoadInfo(String logoImage,BuildContext context){
    return Container(
      child: InkWell(
        child: Container(
          color: YBColor.white,
          height: YBTextStyle.adapterSize58,
          child: Padding(
            padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
            child: Row(
              children: [
                Container(
                  child: Text(
                    YBChineseText.minePinPaiLogoTitle,
                    style: YBTextStyle.TextStyle2F303314,
                  ),
                ),
                Spacer(),
                Container(
                  child: Container(
                    height: YBTextStyle.adapterSize40,
                    width: YBTextStyle.adapterSize40,
                    alignment: Alignment.centerRight,
                    child: ClipRRect(
                      borderRadius: BorderRadius.all(Radius.circular(YBTextStyle.adapterSize20)),
                      child: CachedNetworkImage(
                        imageUrl: logoImage??"",
                      ),
                    ),
                  ),
                ),
                Container(
                  width: YBTextStyle.adapterSize5,
                ),
                Container(
                  child: Image.asset(YBImageStyle.getImagePath('findIconArrowRight')),
                ),
              ],
            ),
          ),
        ),
        onTap: () async {
          YBCameraSelectPopPage.getCameraSelectPop(context);
        },
      ),
    );
  }


  void _editingQuanCengHome(int value){
    Map<String,dynamic> quanCengMap = Map<String,dynamic>();
    quanCengMap['sysCode'] = 'xg_youbang';
    quanCengMap['upStatus'] = value.toString();
    YBMineNetWork.mineQuanCengHomeEditingData(quanCengMap,success:(data){
      print('--$data-');
      bool dataBool = data['body'];
      if (dataBool == true){
        quanCengHomeInputEventBus.fire(YBQuanCengHomeInputEventBus(title: "12",content:value.toString()));
      }
    },fail: (error){
      print('---$error');
    });
  }

}
